package com.sskj.extract;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;

public class ExtractAction extends AnAction {

    @Override
    public void actionPerformed(AnActionEvent e) {
        final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
        VirtualFile[] children = project.getBaseDir().getChildren();
        Config.list.clear();
        for (VirtualFile child : children) {
            for (VirtualFile childChild : child.getChildren()) {
                if (childChild.getName().equals("build.gradle")) {
                    Config.list.add(child.getName());
                    break;
                }
            }
        }
        if (Config.list.isEmpty()) {
            return;
        }
        Config.basePath=project.getBasePath()+"/";
        MainDialog sampleDialogWrapper = new MainDialog(project);
        sampleDialogWrapper.setVisible(true);
    }
}
